package Year22_Month05.day13;

import java.util.LinkedList;
import java.util.Queue;

public class 用队列实现栈 {
    Queue<Integer> a = null;//用来入栈
    Queue<Integer> b = null;//用来出栈
    public 用队列实现栈() {
        a = new LinkedList<>();
        b = new LinkedList<>();
    }

    public void push(int x) {
        //push方法其实就是注意一个地方，你要保证a永远为null
        a.offer(x);
        while(!b.isEmpty()){
            a.offer(b.poll());
        }
        Queue tmp = a;
        a = b;
        b = tmp;
    }

    public int pop() {
        return b.poll();
    }

    public int top() {
        return b.peek();
    }

    public boolean empty() {
        return b.isEmpty();
    }
}
